﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.SharePoint;
using System.Xml.Linq;

namespace SPMetadataManager.ContentTypes
{
    public class Exporter
    {
        public void ExportContentType(string siteUrl, out XElement contentTypes)
        {
            contentTypes = new XElement("ContentTypes");

            try
            {
                contentTypes.SetAttributeValue("SiteCollection", siteUrl);
                using (SPSite site = new SPSite(siteUrl))
                {
                    using (SPWeb web = site.OpenWeb())
                    {
                        foreach (SPContentType con in web.AvailableContentTypes)
                        {
                            XElement contenttype = new XElement("ContentType");
                            contenttype.SetAttributeValue("Name", con.Name);
                            contenttype.SetAttributeValue("Parent", con.Parent.ToString());
                            contenttype.SetAttributeValue("Group", con.Group);
                            contentTypes.Add(contenttype);
                        }
                    }
                }

            }
            catch (Exception e)
            {
            }
        }
    }
}
